<template>
	<div class="content">
		<Collapse v-model="value1">
			<Panel name="1">
				奖池配置
				<div slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="广告值市值：">
								<Input class="w80" v-model="qita.SignReward.content" />
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="kepp(qita.SignReward.id,qita.SignReward.content)" size="large">保　存</Button>
							</div>
						</div>
						<div class="canshu">
							<FormItem label="USDT市值：">
								<Input class="w80" v-model="qita.ShareRewards.content" />
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="kepp(qita.ShareRewards.id,qita.ShareRewards.content)" size="large">保　存</Button>
							</div>
						</div>
						<div class="canshu">
							<FormItem label="发送手续费：">
								BTC &nbsp;
								<Input class="w80" v-model="shouxufei.chargeConfigBtc.content" /> %
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="keppFee(shouxufei.chargeConfigBtc.id,shouxufei.chargeConfigBtc.content)" size="large">保　存</Button>
							</div>
						</div>
						<div class="canshu">
							<FormItem label="提现手续费：">
								ETH &nbsp;
								<Input class="w80" v-model="shouxufei.chargeConfigEth.content" /> %
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="keppFee(shouxufei.chargeConfigEth.id,shouxufei.chargeConfigEth.content)" size="large">保　存</Button>
							</div>
						</div>
						<div class="canshu">
							<FormItem label="禁止提币：">
								<CheckboxGroup v-model="jinzhi">
									<Checkbox :label="4" size="large"><span>USDT</span></Checkbox>
								</CheckboxGroup>
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="keppSend" size="large">保　存</Button>
							</div>
						</div>
						<div class="canshu">
							<FormItem label="广告主基数：">
								<Input class="w80" v-model="qita.commission.content" /> 瓶
							</FormItem>
							<div class="p-10">
								<Button type="primary" @click="kepp(qita.commission.id,qita.commission.content)" size="large">保　存</Button>
							</div>
						</div>
					</Form>
				</div>
			</Panel>
		</Collapse>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				value1: '1',
				qita: {}, // 其他
				jinzhi: [], // 禁止发送
				shouyi: [], // 分享奖励
				incomeNum: '',
				shouxufei: {} // 发送手续费
			}
		},
		methods: {
			// 查询其他参数
			getQt() {
				let token = localStorage.getItem('mytoken')
				this.axios
					.get('parameter/back/config', {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.qita = res.data.data
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 查询发送手续费参数
			getFee() {
				let token = localStorage.getItem('mytoken')
				this.axios
					.get('parameter/charge/config', {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.shouxufei = res.data.data
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 查询禁止发送
			getSend() {
				let token = localStorage.getItem('mytoken')
				this.axios
					.get('parameter/forbid/config', {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.jinzhi = res.data.data.forbidChargeConfigs
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 查询分享收益
			getShouyi() {
				let token = localStorage.getItem('mytoken')
				this.axios
					.get('parameter/node/reward/config', {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.shouyi = res.data.data.nodeRewardConfigs
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 添加分享等级奖励
			addzt(content) {
				let reg = /[^\d^\.]+/g

				let shouyi = reg.test(content)
				if(shouyi) {
					this.$Message.info('请输入正数')
					return false
				}

				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					content: content
				})
				this.axios
					.post('parameter/node/reward/config', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.getShouyi()
							this.incomeNum = null
							this.$Message.info(res.data.message)
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message)
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 删除分享奖励等级
			delzt(id) {
				let token = localStorage.getItem('mytoken')
				this.axios.delete('parameter/node/reward/config/' + id, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.getShouyi()
						this.$Message.info(res.data.message)
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 修改分享奖励等级
			keppzt(id, content) {
				let reg = /[^\d^\.]+/g
				let shouyi = reg.test(content)
				if(shouyi) {
					this.$Message.info('请输入正数')
					return false
				}

				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					id: id,
					content: content
				})
				this.axios.put('parameter/node/reward/config', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.getShouyi()
						this.$Message.info(res.data.message)
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 修改其他参数
			kepp(id, content) {
				let reg = /[^\d^\.]+/g
				let qt = reg.test(content)
				if(qt) {
					this.$Message.info('请输入正数')
					return false
				}

				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					id: id,
					content: content
				})

				this.axios.put('parameter/back/config', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.getQt()
						this.$Message.info(res.data.message)
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 修改发送手续费参数
			keppFee(id, content) {
				let reg = /[^\d^\.]+/g
				let fee = reg.test(content)
				if(fee) {
					this.$Message.info('请输入正数')
					return false
				}

				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					id: id,
					content: content
				})

				this.axios.put('parameter/charge/config', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.getFee()
						this.$Message.info(res.data.message)
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 修改禁止发送配置
			keppSend() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					startList: this.jinzhi
				})
				// console.log(params)
				this.axios.put('parameter/forbid/config', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.getSend()
						this.$Message.info(res.data.message)
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		},
		created() {
			this.getQt()
			this.getFee()
			this.getSend()
			setTimeout(() => {
				this.getShouyi()
			}, 500)
		},
		mounted() {
			this.$Message.config({
				top: 250
			})
		}
	}
</script>

<style lang="less" scoped>
	.p-10 {
		padding-top: 0 !important;
		padding-left: 50px !important;
	}
	
	.w50 {
		width: 50px !important;
	}
	
	.mar {
		margin-left: 5px;
	}
</style>